package com.tomdd.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tomdd.model.entity.Category;
import com.tomdd.model.req.CategoryReq;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
* @author zhongxu
* @description 针对表【category】的数据库操作Mapper
* @createDate 2024-07-17 21:27:40
* @Entity com.tomdd.model.entity.Category
*/
public interface CategoryMapper extends BaseMapper<Category> {

    /**
     * 新增分类
     * @param category 分类对象
     */
    @Insert("insert into category(category_name,category_alias,create_user,create_time,update_time) " +
            "values(#{categoryName},#{categoryAlias},#{createUser},#{createTime},#{updateTime})")
    void add(CategoryReq category);

    /**
     * 根据文章分类id查询分类信息
     *
     * @param id 文章分类id
     * @return 文章分类信息 {@link Category}
     */
    @Select("select * from category where id = #{id}")
    Category findById(@Param("id")Integer id);

    /**
     * 根据文章分类id修改分类信息
     *
     * @param category 分类
     * @return 响应结果
     */
    @Update("update category set category_name=#{data.categoryName}," +
            "category_alias=#{data.categoryAlias},update_time=#{data.updateTime} where id=#{data.id}")
    void updateCategory(@Param("data") Category category);
}




